package com.lanou.student.page;

import java.util.Objects;
import java.util.Scanner;

import com.lanou.student.bean.User;
import com.lanou.student.controller.StudentController;
import com.lanou.student.controller.UserController;
import com.lanou.student.util.CaptchaCode;
import com.lanou.student.util.PasswordUtil;

public class Login {
	private UserController userController;
	private Index index;
	private Scanner sc = new Scanner(System.in);
	
	public Login() {
		userController = new UserController();
		index = new Index();
	}
	public void login() {
		System.out.println("=========登录界面=========");
		Project project = new Project();
		System.out.println("请输入用户名");
		String userName = sc.next();
		System.out.println("请输入密码");
		String password = PasswordUtil.md5(sc.next(), userName);
		System.out.println("请输入验证码");
		String s = CaptchaCode.getCode();
		String code = sc.next();
		User u = userController.getUser(userName, null);
		if (null == u) {
			System.out.println("用户名输入错误");
			return;
		}
		
		if (!Objects.equals(password, u.getPassword())) {
			System.out.println("密码输入错误");
			return;
			
		}
		
		if (!Objects.equals(s, code)) {
			System.out.println("验证码输入错误");
			return;
		}
		
		index.index();
		
	}

}
